﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing {
    import flash.events.*;
    import flash.display.*;
    import flash.text.*;
    import org.aswing.util.*;
    import org.aswing.error.*;
    import flash.ui.*;

    public class JRootPane extends Container {

        protected var defaultButton:JButton;
        protected var mnemonics:HashMap;
        protected var mnemonicJustActed:Boolean;
        protected var keyManager:KeyboardManager;
        private var triggerProxy:InteractiveObject;

        public function JRootPane(){
            setName("JRootPane");
            this.mnemonicJustActed = false;
            layout = new BorderLayout();
            this.mnemonics = new HashMap();
            this.keyManager = new KeyboardManager();
            this.keyManager.init(this);
            this.triggerProxy = this;
            this.setMnemonicTriggerProxy(null);
            addEventListener(Event.REMOVED_FROM_STAGE, this.__removedFromStage);
        }
        public function setDefaultButton(_arg1:JButton):void{
            if (this.defaultButton != _arg1){
                if (this.defaultButton != null){
                    this.defaultButton.repaint();
                };
                this.defaultButton = _arg1;
                this.defaultButton.repaint();
            };
        }
        public function getDefaultButton():JButton{
            return (this.defaultButton);
        }
        public function setMenuBar(_arg1):void{
            throw (new ImpMissError());
        }
        public function getKeyMap():KeyMap{
            return (this.keyManager.getKeyMap());
        }
        override public function getKeyboardManager():KeyboardManager{
            return (this.keyManager);
        }
        public function setKeyMapActived(_arg1:Boolean):void{
            this.keyManager.setEnabled(_arg1);
        }
        public function setMnemonicTriggerProxy(_arg1:InteractiveObject):void{
            if (_arg1 != this.triggerProxy){
                if (this.triggerProxy){
                    this.triggerProxy.removeEventListener(TextEvent.TEXT_INPUT, this.__textInput, true);
                    this.triggerProxy.removeEventListener(KeyboardEvent.KEY_DOWN, this.__keyDown, true);
                };
                this.triggerProxy = _arg1;
                if (_arg1 == null){
                    _arg1 = this;
                };
                _arg1.addEventListener(TextEvent.TEXT_INPUT, this.__textInput, true, 0, true);
                _arg1.addEventListener(KeyboardEvent.KEY_DOWN, this.__keyDown, true, 0, true);
            };
        }
        function registerMnemonic(_arg1:AbstractButton):void{
            if (_arg1.getMnemonic() >= 0){
                this.mnemonics.put(_arg1.getMnemonic(), _arg1);
            };
        }
        function unregisterMnemonic(_arg1:AbstractButton):void{
            if (this.mnemonics.get(_arg1.getMnemonic()) == _arg1){
                this.mnemonics.remove(_arg1.getMnemonic());
            };
        }
        private function __keyDown(_arg1:KeyboardEvent):void{
            var _local4:AbstractButton;
            var _local5:FocusManager;
            this.mnemonicJustActed = false;
            var _local2:uint = _arg1.keyCode;
            if (_local2 == Keyboard.ENTER){
                _local4 = this.getDefaultButton();
                if (_local4 != null){
                    if (((_local4.isShowing()) && (_local4.isEnabled()))){
                        _local4.doClick();
                        this.mnemonicJustActed = true;
                        return;
                    };
                };
            };
            if (stage == null){
                return;
            };
            if ((stage.focus is TextField)){
                if (!this.keyManager.isMnemonicModifierDown()){
                    return;
                };
            };
            var _local3:AbstractButton = this.mnemonics.getValue(int(_local2));
            if (_local3 != null){
                if (((_local3.isShowing()) && (_local3.isEnabled()))){
                    _local3.doClick();
                    _local5 = FocusManager.getManager(stage);
                    if (_local5){
                        _local5.setTraversing(true);
                        _local3.paintFocusRect();
                    };
                    this.mnemonicJustActed = true;
                };
            };
        }
        private function __textInput(_arg1:TextEvent):void{
            if (((this.keyManager.isMnemonicModifierDown()) || (this.keyManager.isKeyJustActed()))){
                _arg1.preventDefault();
            };
        }
        private function __removedFromStage(_arg1:Event):void{
            this.mnemonics.clear();
        }

    }
}//package org.aswing 
